package com.qyhl.webtv.commonlib.item.fuquan;

import android.view.View;
import android.widget.TextView;

import com.qyhl.webtv.basiclib.utils.DateUtils;
import com.qyhl.webtv.basiclib.utils.StringUtils;
import com.qyhl.webtv.commonlib.R;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.news.GlobalNewsBean;
import com.zhy.adapter.recyclerview.base.ItemViewDelegate;
import com.zhy.adapter.recyclerview.base.ViewHolder;

public class ItemFuQuanNoPic implements ItemViewDelegate<GlobalNewsBean> {
    @Override
    public int getItemViewLayoutId() {
        return R.layout.item_fuquan_news_no_pic;
    }

    @Override
    public boolean isForViewType(GlobalNewsBean item, int position) {
        return !item.isHasPicture() && !"0".equals(item.getType()) && !"15".equals(item.getType()) && !"16".equals(item.getType()) && !"17".equals(item.getType()) && !"18".equals(item.getType());
    }

    @Override
    public void convert(ViewHolder holder, GlobalNewsBean bean, int position) {
        holder.setText(R.id.title, bean.getTitle());

        //来源
        TextView origin = holder.getView(com.qyhl.webtv.commonlib.R.id.origin);
        if (StringUtils.isNotEmpty(bean.getOrigin())) {
            origin.setVisibility(View.VISIBLE);
            origin.setText(bean.getOrigin());
        } else {
            origin.setVisibility(View.GONE);
        }

        //时间
        holder.setText(R.id.publish_date, DateUtils.translateToYMd(bean.getPublishDate()));

        //阅读数
        TextView scan = holder.getView(com.qyhl.webtv.commonlib.R.id.scan);
        try {
            int minPlay = Integer.parseInt(CommonUtils.getInstance().getMinPlay());
            if (minPlay == 0) {
                scan.setVisibility(View.GONE);
            } else {
                //判断评论数是否大于最少浏览数
                if (StringUtils.isEmpty(bean.getScanNum() + "")) {
                    scan.setVisibility(View.GONE);
                } else if (bean.getScanNum() >=
                        minPlay) {
                    scan.setText(StringUtils.transformNum(bean.getScanNum() + "") + "阅");
                    scan.setVisibility(View.VISIBLE);
                } else {
                    scan.setVisibility(View.GONE);
                }
            }

        } catch (Exception e) {
            scan.setVisibility(View.GONE);
        }
    }
}
